package cn.b.sky.mes.pp.controller;

import java.io.IOException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.b.sky.mes.pp.enums.OrderStatusCode;
import cn.b.sky.mes.pp.model.condition.ProductionOrderCondition;
import lombok.extern.slf4j.Slf4j;
import org.activiti.engine.ActivitiException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import cn.b.sky.mes.cm.model.MateriaProcessAssign;
import cn.b.sky.mes.cm.model.Material;
import cn.b.sky.mes.cm.model.WorkCenter;
import cn.b.sky.mes.cm.service.MaterialService;
import cn.b.sky.mes.cm.service.ProcessService;
import cn.b.sky.mes.cm.service.WorkCenterService;
import cn.b.sky.common.constants.SystemConstant;
import cn.b.sky.common.exception.ImeException;
import cn.b.sky.common.model.DWZResult;
import cn.b.sky.common.model.Page;
import cn.b.sky.user.SecurityContextUtil;
import cn.b.sky.user.controller.SecurityController;
import cn.b.sky.mes.cm.enums.ECodeEnums;
import cn.b.sky.user.service.ECodeService;
import cn.b.sky.user.service.model.ECode;
import cn.b.sky.mes.pp.model.ProductionControl;
import cn.b.sky.mes.pp.model.ProductionOrder;
import cn.b.sky.mes.pp.service.OrderTypeService;
import cn.b.sky.mes.pp.service.ProductionOrderService;

import com.alibaba.fastjson.JSONObject;

/**
 * <strong>Title : ProductionOrderController.java<br></strong>
 * <strong>Package : cn.b.sky.mes.pp.controller<br></strong>
 * <strong>Description : </strong>@生产订单控制器@<br> 
 * <strong>Create on : 2015年10月6日 上午10:22:43<br></strong>
 * <p>
 * @author dapeng.li<br>
 * @version <strong>v1.0.0</strong><br>
 * <br>
 * <strong>修改历史:</strong><br>
 * 修改人 | 修改日期 | 修改描述<br>
 * -------------------------------------------<br>
 * <br>
 * <br>
 */

@Controller
@RequestMapping(value = "/productionOrder/*")
@Slf4j
public class ProductionOrderController extends SecurityController {

  @Resource
  ProductionOrderService orderService;

  @Resource
  ECodeService eCodeService;

  @Resource
  OrderTypeService orderTypeService;

  @Resource
  WorkCenterService workCenterService;

  @Resource
  MaterialService materialService;

  @Resource
  ProcessService processService;

  /**
   * 
   * <strong>Title : productionOrderList<br></strong>
   * <strong>Description : </strong>生产订单列表<br> 
   * <strong>Create on : 2015-10-12 下午7:01:55<br></strong>
   * <p>
   * @param navTabId
   * @param condition
   * @param productionOrderNum
   * @param model
   * @return
   * String
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("productionOrder_list")
  public String productionOrderList(String navTabId, @ModelAttribute("condition") ProductionOrderCondition condition,
      Model model) {
    condition.setSiteCode(this.getSiteCode());
    List<ECode> ecode = eCodeService.selectECodeList(ECodeEnums.PRODUCTIONORDER_TYPE.getCode(),
        SecurityContextUtil.getLanguageCode());
    //订单类型
    model.addAttribute("orderTypes", orderTypeService.getAllUnlockedOrderTypes(this.getSiteCode()));
    Page page = orderService.getProductionOrdersByCondition(condition);
    model.addAttribute("page", page);
    model.addAttribute("orderStatusECode", ecode);
    model.addAttribute(NAVTABID, navTabId);
    return "pp/productionOrder/productionOrder_list";
  }

  /**
   * 
   * <strong>Title : addProductionOrder<br></strong>
   * <strong>Description : </strong>现在生产订单<br> 
   * <strong>Create on : 2015-10-12 下午7:02:09<br></strong>
   * <p>
   * @param navTabId
   * @param model
   * @return
   * String
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("addProductionOrder")
  public String addProductionOrder(String navTabId, Model model, HttpSession session) {
    //订单状态
    model.addAttribute("orderTypes", orderTypeService.getAllUnlockedOrderTypes(this.getSiteCode()));
    model.addAttribute(NAVTABID, navTabId);
    model.addAttribute("sessionid", session.getId());
    return "pp/productionOrder/productionOrder_add";
  }

  /**
   * 
   * <strong>Title : getProcessByMaterial<br></strong>
   * <strong>Description : </strong>新增编辑订单时选择物料<br> 
   * <strong>Create on : 2015-10-12 下午7:02:21<br></strong>
   * <p>
   * @param materialCode
   * @return
   * DWZResult
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("getProcessByMaterial")
  @ResponseBody
  public DWZResult getProcessByMaterial(String materialCode) {
    if (StringUtils.isBlank(materialCode)) {
      return ajaxError(this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(),
          "failedOp.M,materialCode.C,isNull.M"));
    }
    List<MateriaProcessAssign> materiaProcess = materialService.selectLastProcessByMaterial(this.getSiteCode(),
        materialCode);
    return ajaxDone(materiaProcess);
  }

  /**
   * 
   * <strong>Title : checkedButtonEnable<br></strong>
   * <strong>Description : </strong>检查按钮前置事件@<br> 
   * <strong>Create on : 2015-10-13 下午6:52:55<br></strong>
   * <p>
   * @param productionOrderNum
   * @param type
   * @return
   * DWZResult
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("checkedButtonEnable")
  @ResponseBody
  public DWZResult checkedButtonEnable(String productionOrderNum, String type) {
    ProductionOrder order = orderService.getProductionOrderByPk(this.getSiteCode(), productionOrderNum);
    if (order == null) {
      return ajaxError(this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), SystemConstant.PARAMETERNULL));
    }
    String statusCode = order.getStatuseCode();
    ECode ecode = eCodeService.selectEcodeByECodeTypeAndLanguageCodeAndECode(order.getStatuseCode(),
        ECodeEnums.PRODUCTIONORDER_TYPE.getCode(), SecurityContextUtil.getLanguageCode());
    //编辑
    if ("edit".equals(type) && !OrderStatusCode.CREATE.getValue().equals(statusCode)) {
      return ajaxError(this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "productionOrder_alread.M",
          ecode.geteCodeText()) + this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "notEdit.M"));
    }
    //下达
    if ("issued".equals(type)) {
      //非创建和在制状态的订单不能下达
      if (!OrderStatusCode.CREATE.getValue().equals(statusCode)
          && !OrderStatusCode.PLACE_ORDER.getValue().equals(statusCode)) {
        return ajaxError(this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "productionOrder_alread.M",
            ecode.geteCodeText()) + this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "notIssued.M"));
      }
      if (order.getPlannedQuantity() <= 0) {
        return ajaxError(this
            .getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "hasNot.M,plannedQuantity.C")
            + this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "notIssued.M"));
      }
      //全部下达
      if (order.getPlannedQuantity() <= order.getReleasedQuantity()) {
        return ajaxError(this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(),
            "productionOrder_alreadIssued.M"));
      }
      List<WorkCenter> workCenters = null;
      if (order != null && !StringUtils.isBlank(order.getProcessRev()) && !StringUtils.isBlank(order.getProcessCode())) {
        //没有工作中心不能下达
        workCenters = workCenterService.getAllWorkCenterListByProcessCode(order.getProcessCode(), this.getSiteCode(),
            order.getProcessRev());
      }
      if (workCenters == null || workCenters.size() <= 0) {
        return ajaxError(this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "hasNot.M,workCenter.C")
            + this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "notIssued.M"));
      }
    }
    return ajaxDone(null);
  }

  /**
   * 
   * <strong>Title : editProductionOrder<br></strong>
   * <strong>Description : </strong>编辑生产订单<br> 
   * <strong>Create on : 2015-10-12 下午7:02:40<br></strong>
   * <p>
   * @param navTabId
   * @param model
   * @param productionOrderNum
   * @return
   * String
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("editProductionOrder")
  public String editProductionOrder(String navTabId, Model model, String productionOrderNum, HttpSession session) {
    if (!StringUtils.isBlank(productionOrderNum)) {
      ProductionOrder order = orderService.getProductionOrderByPk(this.getSiteCode(), productionOrderNum);
      order.setAttachment(orderService.getProductionOrderAttachment(this.getSiteCode(), productionOrderNum));
      model.addAttribute("productionOrder", order);
      List<ECode> ecode = eCodeService.selectECodeList(ECodeEnums.PRODUCTIONORDER_TYPE.getCode(),
          SecurityContextUtil.getLanguageCode());
      List<MateriaProcessAssign> process = materialService.selectLastProcessByMaterial(this.getSiteCode(),
          order.getMaterialCode());
      //订单状态
      model.addAttribute("orderTypes", orderTypeService.getAllUnlockedOrderTypes(this.getSiteCode()));
      model.addAttribute("orderStatusECode", ecode);
      model.addAttribute("materiaProcess", process);
      model.addAttribute(NAVTABID, navTabId);
    }
    //附件上传sessionid
    model.addAttribute("sessionid", session.getId());
    return "pp/productionOrder/productionOrder_edit";
  }

  /**
   * 
   * <strong>Title : viewProductionOrder<br></strong>
   * <strong>Description : </strong>查看生产订单<br> 
   * <strong>Create on : 2015-10-12 下午7:02:54<br></strong>
   * <p>
   * @param navTabId
   * @param model
   * @param productionOrderNum
   * @return
   * String
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("viewProductionOrder")
  public String viewProductionOrder(String navTabId, Model model, String productionOrderNum) {
    if (!StringUtils.isBlank(productionOrderNum)) {
      ProductionOrder order = orderService.getProductionOrderByPk(this.getSiteCode(), productionOrderNum);
      order.setAttachment(orderService.getProductionOrderAttachment(this.getSiteCode(), productionOrderNum));
      List<ProductionControl> controls = orderService.getProductionControlsByOrder(this.getSiteCode(),
          productionOrderNum);
      model.addAttribute("orderStatusECode", eCodeService.selectECodeList(ECodeEnums.PRODUCTIONORDER_TYPE.getCode(),
          SecurityContextUtil.getLanguageCode()));

      model.addAttribute(
          "controlStatusECode",
          eCodeService.selectECodeList(ECodeEnums.PRODUCTIONCONTROL_STATUS.getCode(),
              SecurityContextUtil.getLanguageCode()));
      model.addAttribute("productionOrder", order);
      model.addAttribute("orderDetails", controls);
    }
    return "pp/productionOrder/productionOrder_view";
  }

  /**
   * 
   * <strong>Title : deleteProductionOrder<br></strong>
   * <strong>Description : </strong>删除生产订单@<br> 
   * <strong>Create on : 2015-10-12 下午7:03:11<br></strong>
   * <p>
   * @param navTabId
   * @param model
   * @param productionOrderNum
   * @return
   * DWZResult
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("deleteProductionOrder")
  @ResponseBody
  public DWZResult deleteProductionOrder(String navTabId, Model model, String productionOrderNum) {
    if (StringUtils.isBlank(productionOrderNum)) {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(),
          "failedOp.M,productionOrderNum.C,isNull.M"));
    } else {
      ProductionOrder order = orderService.getProductionOrderByPk(this.getSiteCode(), productionOrderNum);
      if (order != null && !OrderStatusCode.CREATE.getValue().equals(order.getStatuseCode())) {
        ECode ecode = eCodeService.selectEcodeByECodeTypeAndLanguageCodeAndECode(order.getStatuseCode(),
            ECodeEnums.PRODUCTIONORDER_TYPE.getCode(), SecurityContextUtil.getLanguageCode());
        return ajaxError(this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "productionOrder_alread.M",
            ecode.geteCodeText()) + this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "notDelete.M"));
      }
      orderService.deleteProductionOrderByPk(this.getSiteCode(), productionOrderNum);
      return ajaxDone(null);
    }
  }

  /**
   * 
   * <strong>Title : saveProductionOrderAttachment<br></strong>
   * <strong>Description : </strong>上传生产订单附件<br> 
   * <strong>Create on : 2016-7-21 下午4:29:53<br></strong>
   * <p>
   * @param file
   * @return
   * DWZResult
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping(value = "saveProductionOrderAttachment")
  public void saveProductionOrderAttachment(
      @RequestParam("productionOrderfile") MultipartFile file, HttpServletResponse response)throws IOException{
    response.setContentType("application/json;charset=UTF-8");
    response.getWriter().print(JSONObject.toJSONString(ajaxDone(orderService.saveProductionOrderAttachment(this.getSiteCode(), file))));
  }

  /**
   * 
   * <strong>Title : saveProductionOrder<br></strong>
   * <strong>Description : </strong>新增保存生产订单<br> 
   * <strong>Create on : 2015-10-12 下午7:03:25<br></strong>
   * <p>
   * @param navTabId
   * @param model
   * @param order
   * @return
   * DWZResult
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("saveProductionOrder")
  @ResponseBody
  public DWZResult saveProductionOrder(String navTabId, Model model, ProductionOrder order) {
    if (order == null) {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(),
          "failedOp.M,productionOrderNum.C,isNull.M"));
    }
    //工艺新增版本
    if (!StringUtils.isBlank(order.getProcessCode())
        && order.getProcessCode().indexOf(SystemConstant.MIDDLE_SPLIT) != -1) {
      setProcessToProductionOrder(order);
    } else {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "parameterError.M"));
    }
    if (!order.getPlannedendDateTime().after(order.getPlannedstartDateTime())) {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "planDateTimeError.M"));
    }
    this.setCreateInfo(order);
    //创建
    order.setStatuseCode(OrderStatusCode.CREATE.getValue());
    orderService.saveProductionOrder(order);
    return dialogAjaxDone(navTabId, null, null, null);
  }

  private void setProcessToProductionOrder(ProductionOrder order) {
    String[] str = order.getProcessCode().split(SystemConstant.MIDDLE_SPLIT);
    order.setProcessCode(str[0]);
    order.setProcessRev(str[1]);
  }

  /**
   * 
   * <strong>Title : modifyProductionOrder<br></strong>
   * <strong>Description : </strong>修改保存生产订单<br> 
   * <strong>Create on : 2015-10-12 下午7:03:38<br></strong>
   * <p>
   * @param navTabId
   * @param model
   * @param order
   * @return
   * DWZResult
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("modifyProductionOrder")
  @ResponseBody
  public DWZResult modifyProductionOrder(String navTabId, Model model, ProductionOrder order) {
    if (order == null || StringUtils.isBlank(order.getProductionOrderNum())) {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(),
          "failedOp.M,productionOrderNum.C,isNull.M"));
    }
    //工艺新增版本
    if (!StringUtils.isBlank(order.getProcessCode())
        && order.getProcessCode().indexOf(SystemConstant.MIDDLE_SPLIT) != -1) {
      setProcessToProductionOrder(order);
    } else {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "parameterError.M"));
    }
    if (!order.getPlannedendDateTime().after(order.getPlannedstartDateTime())) {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), "planDateTimeError.M"));
    }
    order.setSiteCode(this.getSiteCode());
    order.setLanguageCode(getCurrentLanguage());
    this.setCreateInfo(order);
    if (order.getProductionlotNum() == null) {
      order.setProductionlotNum("");
    }
    try {
      orderService.doModifyProductionOrder(order);
    } catch (ImeException e) {
      log.error("{}", e);
      return ajaxError(this.getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), e.getErrorCode(),
          e.getParameters()));
    }
    return dialogAjaxDone(navTabId, null, null, null);
  }

  /**
   * 
   * <strong>Title : decomposeProductionOrder<br></strong>
   * <strong>Description : </strong>生产订单分解sfc<br> 
   * <strong>Create on : 2016-5-13 下午4:53:08<br></strong>
   * <p>
   * @param productionOrderNum
   * @param navTabId
   * @param model
   * @return
   * String
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("decomposeProductionOrder")
  public String decomposeProductionOrder(String productionOrderNum, String navTabId, Model model) {

    ProductionOrder order = orderService.getProductionOrderByPk(this.getSiteCode(), productionOrderNum);
    if (null != order && !StringUtils.isBlank(order.getProcessRev()) && !StringUtils.isBlank(order.getProcessCode())) {
      List<WorkCenter> workCenters = workCenterService.getAllWorkCenterListByProcessCode(order.getProcessCode(),
          this.getSiteCode(), order.getProcessRev());
      model.addAttribute("workCenters", workCenters);
    }
    //工作中心加上物料的默认工作中心,
    Material material = materialService.selectMaterial(this.getSiteCode(), order.getMaterialCode());
    model.addAttribute("defalutWorkCenters", material.getWorkCenterCode());
    model.addAttribute("productionOrder", order);
    model.addAttribute(NAVTABID, navTabId);
    //下达
    return "pp/productionOrder/productionOrder_decompose_new";
  }

  @RequestMapping("saveProductionControl")
  @ResponseBody
  public DWZResult saveProductionControl(String navTabId, Model model, ProductionOrder order) {
    if (order == null || StringUtils.isBlank(order.getProductionOrderNum())) {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(),
          "failedOp.M,productionOrderNum.C,isNull.M"));
    }
    if (order.getControls() == null || order.getControls().size() <= 0) {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(),
          "failedOp.M,order_notorderDetails.M"));
    }
    order.setSiteCode(this.getSiteCode());
    setCreateInfo(order);
    try {
      orderService.doSplitProduction(order);
    } catch (ImeException e) {
      log.error("{}", e);
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), e.getErrorCode(), e.getParameters()));
    } catch (ActivitiException e) {
      log.error("{}", e);
      return navTabAjaxError();
    }
    return dialogAjaxDone(navTabId, null, null, null);
  }

  /**
   * 
   * <strong>Title : backissuedProductionOrder<br></strong>
   * <strong>Description : </strong>撤回下达<br> 
   * <strong>Create on : 2016-5-17 下午2:55:28<br></strong>
   * <p>
   * @param navTabId
   * @param model
   * @param productionOrderNum
   * @return
   * DWZResult
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("backissuedProductionOrder")
  @ResponseBody
  public DWZResult backissuedProductionOrder(String navTabId, Model model, String productionOrderNum) {
    if (StringUtils.isBlank(productionOrderNum)) {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(),
          "failedOp.M,productionOrderNum.C,isNull.M"));
    }
    try {
      orderService.doBackProductionOrder(productionOrderNum, this.getSiteCode());
    } catch (ImeException e) {
      log.error("{}", e);
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), e.getErrorCode(), e.getParameters()));
    }

    return ajaxDone(null);

  }

  @RequestMapping(value = "showReport")
  public String showReport(Model model, String navTabId) {
    model.addAttribute(NAVTABID, navTabId);
    return "common/batchjobReport";
  }

  @RequestMapping(value = "productionArchives")
  public String productionArchives(String productionNum, Model model, String navTabId) {
    if (!StringUtils.isBlank(productionNum)) {
      ProductionOrder order = orderService.getProductionOrderByPk(this.getSiteCode(), productionNum);
      if (order != null) {
        model.addAttribute("operationArchives",
            orderService.drawProcessOperation(this.getSiteCode(), order.getProcessCode(), order.getProcessRev()));
      }
      model.addAttribute("productionOrder", order);
    }
    model.addAttribute("productionNum", productionNum);
    model.addAttribute(NAVTABID, navTabId);
    return "/pp/archives/production_archives";
  }

  /**
   * 
   * <strong>Title : closeProductOrder<br></strong>
   * <strong>Description : </strong>强制关闭<br> 
   * <strong>Create on : 2016-1-19 下午4:14:00<br></strong>
   * <p>
   * @param model
   * @param navTabId
   * @param productionOrderNum
   * @return
   * DWZResult
   * @throws 
   * @author lidapeng<br>
   * @version <strong>v1.0.0</strong><br>
   * <br>
   * <strong>修改历史:</strong><br>
   * 修改人 | 修改日期 | 修改描述<br>
   * -------------------------------------------<br>
   * <br>
   * <br>
   */
  @RequestMapping("closeProductionOrder")
  @ResponseBody
  public DWZResult closeProductionOrder(Model model, String navTabId, String productionOrderNum) {
    if (StringUtils.isBlank(productionOrderNum)) {
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), SystemConstant.PARAMETERNULL));
    }
    try {
      orderService.doCloseProductionOrder(this.getSiteCode(), productionOrderNum);
    } catch (ImeException e) {
      log.error("{}", e);
      return ajaxError(getImeViewMessageI18n(SecurityContextUtil.getLanguageCode(), e.getErrorCode(), e.getParameters()));
    }

    return ajaxDone(null);
  }

}
